#!/usr/bin/python

# InnerSpace
# Copyright (C) 1999-2006 Phil Christensen
#
# $Id: test_export.py 66 2006-11-18 19:50:36Z phil $
#
# See LICENSE for details

import unittest, string, time, os, os.path, difflib

from inner.space import registry, entity, errors, external, minimal, prop, auth

class ImportExportTestCase(unittest.TestCase):
	def setUp(self):
		self.registry = registry.Registry()
		auth.set_test_registry(self.registry)
		minimal.init(self.registry, os.path.join(os.getcwd(), 'verbs'))
		self.test_object = entity.Entity("Test Object")
		self.test_object.add_property('test', "{u'north': None}", self.registry.get('class_wizard'), prop.EVAL_CODE)
		self.registry.put(self.test_object)

	def tearDown(self):
		self.registry = None
	
	def test_cycle(self):
		exported_data = external.export(self.registry)
		
		test_registry = registry.Registry(True)
		external.load(test_registry, exported_data);
		imported_data = external.export(test_registry)
		try:
			assert exported_data == imported_data, "Exported data changed through import/export cycle."
		except AssertionError, e:
			for line in difflib.unified_diff(exported_data.split("\n"), imported_data.split("\n")):
				print line
			raise e

if(__name__ == '__main__'):
	unittest.main()